﻿@inherits BaseComponent
<nav class="@ClassNames" style="@StyleNames" @attributes="@Attributes">
    @if ( Data != null )
    {
        <SidebarContent>
            @if ( Data.Brand?.Text != null || Data.Brand?.To != null )
            {
                <SidebarBrand>
                    <a href="@(Data.Brand?.To ?? string.Empty)">@Data.Brand?.Text</a>
                </SidebarBrand>
            }
            @if ( Data.Items != null )
            {
                <SidebarNavigation>
                    @foreach ( var item in Data.Items )
                    {
                        <SidebarItem @key="@item">
                            <SidebarLink To="@item.To" Title="@item.Tooltip" Visible="@item.Visible" Toggled="@(( isOpen ) => { item.Visible = isOpen; })">
                                @if ( item.Icon != null )
                                {
                                    <Icon Name="item.Icon" />
                                }
                                @item.Text
                            </SidebarLink>
                            @if ( item.SubItems != null )
                            {
                                <SidebarSubItem @ref="item.SubItemReference" Visible="@item.Visible">
                                    @foreach ( var subItem in item.SubItems )
                                    {
                                        <SidebarItem @key="@subItem">
                                            <SidebarLink To="@subItem.To">
                                                @if ( subItem.Icon != null )
                                                {
                                                    <Icon Name="subItem.Icon" />
                                                }
                                                @subItem.Text
                                            </SidebarLink>
                                        </SidebarItem>
                                    }
                                </SidebarSubItem>
                            }
                        </SidebarItem>
                    }
                </SidebarNavigation>
            }
        </SidebarContent>
    }
    else
    {
        @ChildContent
    }
</nav>
